287A - IQ Test - CodeForces Solution


brute force implementation *1100

Please click on ads to support us..

Python Code:

f = 0
a = [0] * 4
for i in range(4):
    a[i] = list(input())
    for j in range(4):
         a[i][j] = 1 if  a[i][j] == "#" else -1
    if i != 0:
        for j in range(3):
            if a[i - 1][j] + a[i][j] + a[i - 1][j + 1] + a[i][j + 1] == 0:
                continue
            else:
                f = 1
                break
    if f == 1:
        break
if f == 0:
    print("NO")
else:
    print('YES')

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int long long int 
#define vi(v) vector<int>v;
#define vec(v,n) vector<int>v(n);
#define vii(v) vector<ll>v;
#define input(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,m,n) for(int i=m;i<n;i++)
#define UMAP(ump) unordered_map<int,int>ump; 
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define SORT(V) sort(v.begin(),v.end());
#define SORT_ARRAY(arr,n) sort(arr,arr+n);
void print_array(int*arr,int n){
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}cout<<endl;
}
void print_vector(vector<int>v){
for(auto it : v){
cout<<it<<" ";
}cout<<endl;
}



void solve(){

    vector<vector<int>>v(4,vector<int>(4,0));
    rep(i,0,4){
        rep(j,0,4){
            char c;
            cin>>c;
            if(c=='#'){
                v[i][j]=0;
                
            }
            else{
                v[i][j]=1;
            }
        }
    }


    rep(i,0,3){
        rep(j,0,3){
            int sum=v[i][j]+v[i][j+1]+v[i+1][j]+v[i+1][j+1];
            if(sum==1 || sum==3 || sum==0 || sum==4){
                cout<<"YES"<<endl;
                return;
            }

        }
    }

    cout<<"NO"<<endl;
    
    
    
}
int32_t main(){
fast
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}


Comments

Submit
0 Comments
More Questions

102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths
50. Pow(x, n)
43. Multiply Strings
34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort